<template>
  <ul class="right-list-container">
    <li v-for="(item, index) in list" :key="index">
      <span @click="handleClick(item)" :class="{ active: item.isSelect }">{{
        item.name
      }}</span>
      <span
        @click="handleClick(item)"
        v-if="item.aside"
        class="aside"
        :class="{ active: item.isSelect }"
        >{{ item.aside }}</span
      >
      <RightList :list="item.children" @select="handleClick" />
    </li>
  </ul>
</template>

<script>
export default {
  // 递归组件必须写name，不让不知道递归的是谁
  name: "RightList",
  props: {
    list: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {};
  },
  methods: {
    handleClick(item) {
      if (item.isSelect) return;
      this.$emit("select", item);
    },
  },
};
</script>

<style scoped lang="less">
@import "~@/styles/var.less";

.right-list-container {
  margin-left: 1em;
  li {
    min-height: 40px;
    line-height: 40px;
    cursor: pointer;
    .active {
      color: @warn;
      font-weight: bold;
    }
    .aside {
      font-size: 12px;
      margin-left: 1em;
      color: @gray;
    }
  }
}
</style>
